home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / customs / swap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-15  |  6.7 KB  |  292 lines

  1. /*-
  2.  * rpc.c --
  3.  *    Remote Procedure Call byte-swapping functions
  4.  *
  5.  * Copyright (c) 1988, 1989 by the Regents of the University of California
  6.  * Copyright (c) 1988, 1989 by Adam de Boor
  7.  * Copyright (c) 1989 by Berkeley Softworks
  8.  *
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any non-commercial purpose
  11.  * and without fee is hereby granted, provided that the above copyright
  12.  * notice appears in all copies.  The University of California,
  13.  * Berkeley Softworks and Adam de Boor make no representations about
  14.  * the suitability of this software for any purpose.  It is provided
  15.  * "as is" without express or implied warranty.
  16.  *
  17.  */
  18. #ifndef lint
  19. static char *rcsid =
  20. "$Id: swap.c,v 1.4 89/11/14 13:46:22 adam Exp $ SPRITE (Berkeley)";
  21. #endif lint
  22.  
  23. #include    "customsInt.h"
  24.  
  25. /*-
  26.  *-----------------------------------------------------------------------
  27.  * Swap_Timeval --
  28.  *    Swap the two elements of a struct timeval.
  29.  *
  30.  * Results:
  31.  *    None.
  32.  *
  33.  * Side Effects:
  34.  *    The elements are swapped.
  35.  *
  36.  *-----------------------------------------------------------------------
  37.  */
  38. void
  39. Swap_Timeval (len, data)
  40.     int                  len;
  41.     struct timeval    *data;
  42. {
  43.     Rpc_SwapLong(sizeof(data->tv_sec), &data->tv_sec);
  44.     Rpc_SwapLong(sizeof(data->tv_usec), &data->tv_usec);
  45. }
  46.  
  47. /*-
  48.  *-----------------------------------------------------------------------
  49.  * Swap_Avail --
  50.  *    Byte-swap all fields of an Avail_Data structure.
  51.  *
  52.  * Results:
  53.  *    None.
  54.  *
  55.  * Side Effects:
  56.  *    Ditto.
  57.  *
  58.  *-----------------------------------------------------------------------
  59.  */
  60. void
  61. Swap_Avail (len, data)
  62.     int              len;
  63.     Avail_Data      *data;
  64. {
  65.     Rpc_SwapLong(sizeof(data->changeMask), &data->changeMask);
  66.     Rpc_SwapLong(sizeof(data->idleTime), &data->idleTime);
  67.     Rpc_SwapLong(sizeof(data->swapPct), &data->swapPct);
  68.     Rpc_SwapLong(sizeof(data->loadAvg), &data->loadAvg);
  69.     Rpc_SwapLong(sizeof(data->imports), &data->imports);
  70. }
  71.  
  72. /*-
  73.  *-----------------------------------------------------------------------
  74.  * Swap_Host --
  75.  *    Byte-swap a Host_Data structure.
  76.  *
  77.  * Results:
  78.  *    None.
  79.  *
  80.  * Side Effects:
  81.  *    Ditto.
  82.  *
  83.  *-----------------------------------------------------------------------
  84.  */
  85. void
  86. Swap_Host (len, data)
  87.     int              len;
  88.     Host_Data      *data;
  89. {
  90.     Rpc_SwapShort(sizeof(data->uid), &data->uid);
  91.     Rpc_SwapShort(sizeof(data->flags), &data->flags);
  92. }
  93.  
  94. /*-
  95.  *-----------------------------------------------------------------------
  96.  * Swap_ExportPermit --
  97.  *    Byte-swap an ExportPermit structure.
  98.  *
  99.  * Results:
  100.  *    None.
  101.  *
  102.  * Side Effects:
  103.  *    Ditto.
  104.  *
  105.  *-----------------------------------------------------------------------
  106.  */
  107. void
  108. Swap_ExportPermit (len, data)
  109.     int              len;
  110.     ExportPermit  *data;
  111. {
  112.     Rpc_SwapLong(sizeof(data->addr), (long *)&data->addr);
  113.     Rpc_SwapLong(sizeof(data->id), &data->id);
  114. }
  115.  
  116. /*-
  117.  *-----------------------------------------------------------------------
  118.  * Swap_WayBill --
  119.  *    Swap a WayBill structure and its associated data.
  120.  *
  121.  * Results:
  122.  *    None.
  123.  *
  124.  * Side Effects:
  125.  *    Ditto.
  126.  *
  127.  *-----------------------------------------------------------------------
  128.  */
  129. void
  130. Swap_WayBill (len, data)
  131.     int              len;
  132.     WayBill       *data;
  133. {
  134.     register char *cp;
  135.     register int  i;
  136.     register long *lp;
  137.  
  138.     Rpc_SwapLong(sizeof(data->id), &data->id);
  139.     Rpc_SwapShort(sizeof(data->port), &data->port);
  140.     Rpc_SwapShort(sizeof(data->ruid), &data->ruid);
  141.     Rpc_SwapShort(sizeof(data->euid), &data->euid);
  142.     Rpc_SwapShort(sizeof(data->rgid), &data->rgid);
  143.     Rpc_SwapShort(sizeof(data->egid ), &data->egid);
  144.     Rpc_SwapLong(sizeof(data->umask), &data->umask);
  145.     Rpc_SwapLong(sizeof(data->ngroups), &data->ngroups);
  146.     for (i = data->ngroups, lp = data->groups; i >= 0; i--, lp++) {
  147.     Rpc_SwapLong(sizeof(*lp), lp);
  148.     }
  149.     /*
  150.      * Skip the cwd and the file to execute
  151.      */
  152.     cp = (char *)&data[1];
  153.     cp += strlen(cp) + 1;
  154.     cp += strlen(cp) + 1;
  155.     lp = Customs_Align(cp, long *);
  156.     /*
  157.      * Swap the number of arguments
  158.      */
  159.     Rpc_SwapLong(sizeof(*lp), lp);
  160.     for (cp = (char *)&lp[1], i = *lp; i >= 0; i--) {
  161.     cp += strlen(cp) + 1;
  162.     }
  163.  
  164.     /*
  165.      * Swap the number of environment variables
  166.      */
  167.     lp = Customs_Align(cp, long *);
  168.     Rpc_SwapLong(sizeof(*lp), lp);
  169. }
  170.  
  171. /*-
  172.  *-----------------------------------------------------------------------
  173.  * Swap_Kill --
  174.  *    Byte-swap a Kill_Data structure.
  175.  *
  176.  * Results:
  177.  *    None.
  178.  *
  179.  * Side Effects:
  180.  *    Ditto.
  181.  *
  182.  *-----------------------------------------------------------------------
  183.  */
  184. void
  185. Swap_Kill (len, data)
  186.     int              len;
  187.     Kill_Data      *data;
  188. {
  189.     Rpc_SwapLong(sizeof(data->id), &data->id);
  190.     Rpc_SwapLong(sizeof(data->signo), &data->signo);
  191. }
  192.  
  193. /*-
  194.  *-----------------------------------------------------------------------
  195.  * Swap_RegPacket --
  196.  *
  197.  * Results:
  198.  *
  199.  * Side Effects:
  200.  *
  201.  *-----------------------------------------------------------------------
  202.  */
  203. void
  204. Swap_RegPacket (len, data)
  205.     int              len;
  206.     char          *data;
  207. {
  208.     register long *lp;
  209.  
  210.     /*
  211.      * Skip hostname
  212.      */
  213.     data += strlen(data)+1;
  214.     lp = Customs_Align(data, long *);
  215.  
  216.     Rpc_SwapLong(sizeof(*lp), lp);  /* Machine architecture */
  217.     lp++;
  218.     Rpc_SwapLong(sizeof(*lp), lp);  /* Number of clients */
  219. }
  220.  
  221. /*-
  222.  *-----------------------------------------------------------------------
  223.  * Swap_Info --
  224.  *
  225.  * Results:
  226.  *
  227.  * Side Effects:
  228.  *
  229.  *-----------------------------------------------------------------------
  230.  */
  231. void
  232. Swap_Info (len, data)
  233.     int              len;
  234.     register long *data;
  235. {
  236.     register int  i, j;
  237.  
  238.     /*
  239.      * Get number of hosts in i first, then swap it.
  240.      */
  241.     i = *data;
  242.     Rpc_SwapLong(sizeof(*data), data);
  243.  
  244.     data++;
  245.  
  246.     while (i > 0) {
  247.     data += strlen((char *)data) + 1;
  248.     data = Customs_Align(data, long *);
  249.     Rpc_SwapLong(sizeof(*data), data);      /* Availability */
  250.     data++;
  251.     Rpc_SwapLong(sizeof(*data), data);      /* Availability rating */
  252.     data++;
  253.     Rpc_SwapLong(sizeof(*data), data);      /* Architecture */
  254.     data++;
  255.     j = *data;
  256.     Rpc_SwapLong(sizeof(*data), data);      /* Number of clients */
  257.     data++;
  258.  
  259.     while (j > 0) {
  260.         Rpc_SwapLong(sizeof(*data), data);
  261.         data++;
  262.         j--;
  263.     }
  264.     i--;
  265.     }
  266.     Rpc_SwapLong(sizeof(*data), data);    /* Last Allocated */
  267. }
  268.  
  269. /*-
  270.  *-----------------------------------------------------------------------
  271.  * Swap_AvailInt --
  272.  *    Byte-swap an internal Avail packet.
  273.  *
  274.  * Results:
  275.  *    None.
  276.  *
  277.  * Side Effects:
  278.  *    Ditto.
  279.  *
  280.  *-----------------------------------------------------------------------
  281.  */
  282. void
  283. Swap_AvailInt (len, data)
  284.     int              len;
  285.     Avail         *data;
  286. {
  287.     Rpc_SwapLong(sizeof(data->addr), &data->addr);
  288.     Swap_Timeval(sizeof(data->interval), &data->interval);
  289.     Rpc_SwapLong(sizeof(data->avail), &data->avail);
  290.     Rpc_SwapLong(sizeof(data->rating), &data->rating);
  291. }
  292.